#define THIS_FILE "fn_x_update_target.sqf"
#include "x_setup.sqf"
private ["_target","_display","_textctrl","_text","_end_pos","_target_array2","_leader","_camps"];

PARAMS_1(_target);

disableSerialization;

_display = __uiGetVar(X_TELE_DIALOG);
_textctrl = _display displayCtrl 100110;

if (GVAR(x_loop_end)) exitWith {};

_text = "";
_text2 = "";
_end_pos = position player;
switch (_target) do {
	case 0: {
		switch (GVAR(tele_dialog)) do {
			case 0: {
				_text = (localize "STR_DOM_MISSIONSTRING_604");
				GVAR(beam_target) = 0;
#ifndef __TT__
				_end_pos = position GVAR(FLAG_BASE);
#else
				_end_pos = if (GVAR(player_side) == blufor) then {position GVAR(WFLAG_BASE)} else {position GVAR(EFLAG_BASE)};
#endif
			};
			case 1: {
				_text = (localize "STR_DOM_MISSIONSTRING_605");
				GVAR(beam_target) = 1;
				_end_pos = position (missionNamespace getVariable (GVAR(mob_respawns) select 0));
			};
			case 2: {
				_text = (localize "STR_DOM_MISSIONSTRING_606");
				GVAR(beam_target) = 0;
#ifndef __TT__
				_end_pos = position GVAR(FLAG_BASE);
#else
				_end_pos = if (GVAR(player_side) == blufor) then {position GVAR(WFLAG_BASE)} else {position GVAR(EFLAG_BASE)};
#endif
			};
		};
	};
	case 1: {
		_text = switch (GVAR(tele_dialog)) do {
			case 0: {(localize "STR_DOM_MISSIONSTRING_607")};
			case 1: {(localize "STR_DOM_MISSIONSTRING_605")};
			case 2: {(localize "STR_DOM_MISSIONSTRING_605")};
		};
		GVAR(beam_target) = 1;
		_end_pos = position (missionNamespace getVariable (GVAR(mob_respawns) select 0));
	};
	case 2: {
		_text = switch (GVAR(tele_dialog)) do {
			case 0: {(localize "STR_DOM_MISSIONSTRING_608")};
			case 1: {(localize "STR_DOM_MISSIONSTRING_609")};
			case 2: {(localize "STR_DOM_MISSIONSTRING_609")};
		};
		GVAR(beam_target) = 2;
		_end_pos = position (missionNamespace getVariable (GVAR(mob_respawns) select 1));
	};
	// TYRGHEN
	case 3: {
		__TargetInfo
		_text = switch (GVAR(tele_dialog)) do {
			case 0: {(localize "STR_DOM_MISSIONSTRING_2006")};
			case 1: {(localize "STR_DOM_MISSIONSTRING_2006")};
			case 2: {(localize "STR_DOM_MISSIONSTRING_2006")};
		};
		GVAR(beam_target) = 3;
		_end_pos = getPos player;
		if (GVAR(with_dynamic_teleport) == 1) then {
			if (GVAR(player_leader_var) != "" && {!isnull (missionNameSpace getVariable GVAR(player_leader_var))}) then {
				_leader = (missionNameSpace getVariable GVAR(player_leader_var));
				if (alive _leader && !(GV(_leader,xr_pluncon)) && {(GVAR(teleport_in_town) == 0 || ((_target_array2 select 0) distance (vehicle _leader)) >= (_target_array2 select 2))}) then {
					_end_pos = position (_leader);
				};
			};
		} else {
			_leader = leader (group player);
			if (alive _leader && !(GV(_leader,xr_pluncon)) && {(GVAR(teleport_in_town) == 0 || ((_target_array2 select 0) distance (vehicle _leader)) >= (_target_array2 select 2))}) then {
				_end_pos = position (_leader);
			};
		};
	};
	// TYRGHEN
	case 4: {
		_camps = +(__XJIPGetVar(GVAR(currentcamps)));
		if (!(isNil "_camps") && {count _camps > 0}) then {
			for "_i" from 0 to (count _camps - 1) do {
				if (((_camps select _i) getVariable [QGVAR(SIDE),GVAR(enemy_side)]) != GVAR(own_side_trigger_alt)) then {
					_camps set [_i,objNull];
				};
			};
			_camps = _camps - [objNull];
		};
		_text = (localize "STR_DOM_MISSIONSTRING_2079");
		GVAR(beam_target) = 4;
		_end_pos = getPos player;
		if (count _camps > 0) then {
			_end_pos = position (_camps call FUNC(randomArrayVal));
		};
	};
};

_textctrl ctrlSetText _text;

_ctrlmap = _display displayCtrl 100104;
ctrlMapAnimClear _ctrlmap;

_start_pos = position player;
_ctrlmap ctrlmapanimadd [0.0, 1.00, _start_pos];
_ctrlmap ctrlmapanimadd [1.2, 1.00, _end_pos];
_ctrlmap ctrlmapanimadd [0.5, 0.30, _end_pos];
ctrlmapanimcommit _ctrlmap;